package com.itheima;

public class ArrayTest4 {
    public static void main(String[] args) {
        //目标:完成斗地主的做牌和洗牌
        start();
    }

    public static void start(){
        //1.创建一个动态初始化的数组存储54张牌
        String[] poker=new String[54];  //此时里面默认值是null

        //2.准备四种花色,还有点数,再开始做牌存入数组中去
        String[] color={"♠","♥","♦","♣"};
        String[] number={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        //3.遍历点数,再遍历花色
        int index=0;    //定义一个变量记录牌存储的索引位置
        for (int i = 0; i < number.length; i++) {
            for (int j = 0; j < color.length; j++) {
                //4.将牌存入数组
                poker[index++]=color[j]+number[i];      //等于index++了.最后index在55的位置
            }
        }

        //4.将小大王存入数组
        poker[index++]="🤦‍♀️";
        poker[index]="🤦‍♂️";

        //5.打印牌
        System.out.println("新牌:");
        for (int i = 0; i < poker.length; i++) {
            System.out.println(poker[i] + " ");     //println结尾自带换行符,print不自带
        }
        System.out.println();   //换行

        //6.洗牌
        for (int i = 0; i < poker.length; i++) {
            //随机获得两个索引
            int index1=(int)(Math.random()* poker.length);  //[0,54)
            int index2=(int)(Math.random()* poker.length);  //[0,54)

            //每次都需要让index1和index2这两个索引处的数据进行交换
            String temp = poker[index2];
            poker[index2] = poker[index1];
            poker[index1] = temp;

        }

        System.out.println("洗牌后:");
        for (int i = 0; i < poker.length; i++) {
            System.out.println(poker[i] + " ");
        }
    }
}
